home *** CD-ROM | disk | FTP | other *** search
- /*
- ** $VER: PluginFuncs.c 1.00 (9.8.1999)
- **
- ** Functions for the #?.plugin
- **
- ** (C) Copyright 1999 Felix Schwarz
- ** All Rights Reserved.
- */
-
- #define __USE_SYSBASE // perhaps only recognized by SAS/C
-
- #include <exec/types.h>
- #include <exec/memory.h>
-
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <intuition/intuition.h>
- #include <libraries/gadtools.h>
- #include <clib/gadtools_protos.h>
-
- #include <libraries/dos.h>
- #include <dos/dos.h>
-
- #include "PluginFuncs.h"
- #include <fxPAINT/fxPLUGIN.h>
- #include <fxPAINT/fxPAINT_API.h>
- #include "compiler.h"
-
- #include <fxPAINT/fxPAINT_API.c>
-
- /************ Your structures **************/
- struct settings
- {
- long xor_value;
- };
-
- struct handle_struct
- {
- struct Window *win;
- struct fsbitmap *content;
- };
-
- /************* INIZIALIZATION ROUTINES *****************/
-
- /* Ok, this one is very important. It passes information about the features
- of your plugin to fxPAINT and is called during fxPAINTs startup. */
-
- struct PluginInfo * __saveds ASM FXPlug_Info(register __d1 ULONG type, register __d2 struct PluginInit *plg)
- {
- struct PluginInfo *p_pinf=NULL;
-
- initfunc(plg);
-
- if (p_pinf=AllocVec(sizeof(struct PluginInfo), MEMF_ANY|MEMF_CLEAR))
- {
- /* Version information */
- p_pinf->int_version=1; // .. for your code
- p_pinf->int_revision=0; // .. for your code
- p_pinf->fxp_version=1; // .. of the used fxPAINT SDK
-
- /* Various Information on the Plugin */
- p_pinf->plugin_name ="Example Plugin";
- p_pinf->filter_name ="XOR";
- p_pinf->saver_name ="PPM (ExamplePlugin)";
- p_pinf->plugin_description="Example Plugin: XOR, loader, saver, launchable";
- p_pinf->author_name ="Felix Schwarz";
- p_pinf->author_company ="Innovative";
- p_pinf->author_copyright ="©1999 by Felix Schwarz/Innovative";
- p_pinf->logo_file ="Plugins/Logo/examplePLUG";
- p_pinf->help_file =NULL; /* No help file, otherwhise specify
- something like "PROGDIR:Plugins/Help/example/example.guide"
- */
-
- /* Detailed information on the kind of plugin */
- /* Note: You can combine several types or take only one :) */
- p_pinf->plugin_kind = PLG_FILTER|PLG_LOADER|PLG_SAVER|PLG_HAVEPORTS|PLG_LAUNCHABLE;
- //p_pinf->plugin_flags = PLG_FLG_LAUNCHMEATSTART; /* Start the FXPlug_Launch function right
- // after fxPAINT has fully started up ! */
-
- if (type==0)
- {
- /* This call is unique */
- p_pinf->plugin_space = AllocVec(sizeof(struct handle_struct),MEMF_ANY|MEMF_CLEAR); /* Additional needed space ..
- is freed in FXPlug_Bye and
- can e.g. contain a structure,
- that contains pointers to windows,
- ports, etc. .. */
- }
- else
- {
- /* This call isn`t unique! DON`T ALLOCATE plugin_space!*/
-
- }
- }
-
- return(p_pinf);
- }
-
- /* This clears the memory, that was used to pass the info. */
-
- void __saveds ASM FXPlug_FreeInfo(register __d1 APTR mem, register __d2 struct PluginInit *plg)
- {
- initfunc(plg);
-
- if (mem)
- {
- FreeVec(mem);
- }
- }
-
- /* This function is the last one called, before fxPAINT quits */
-
- void __saveds ASM FXPlug_Bye(register __d1 struct PluginBye *plb)
- {
- struct handle_struct *hs;
- initfunc(plb->pli);
-
- if (plb->allocatedmem)
- {
- /* The adress, that was p_pinf->plugin_space once .. if you have
- any OS-ressources`s adresses in here, like that of windows, ports,
- etc., free them now and then free the memory. */
-
- hs=plb->allocatedmem;
-
- if (hs->win)
- {
- remport_sigmask(hs->win->UserPort->mp_SigBit, plb->pli->pluginid);
- CloseWindow(hs->win);
- hs->win=NULL;
- }
-
- if (hs->content)
- {
- fs_freebitmap(hs->content);
- hs->content=NULL;
- }
-
- FreeVec(plb->allocatedmem);
- }
- }
-
- /************************** EFFECTS *********************/
-
- /* Initialize the plugin for the effects */
-
- APTR __saveds ASM FXPlug_InitPlugin(register __d1 struct PluginInit *plg)
- {
- /* Return address of space allocated for saving
- infos of the Plugin to */
-
- initfunc(plg);
-
- return (CstAllocVec(sizeof(struct settings),MEMF_ANY|MEMF_CLEAR));
- }
-
- /* .. and free any memory, that was allocated for the effect. Very useful,
- if you are using structures to store pointers in it :) */
-
- void __saveds ASM FXPlug_ClosePlugin(register __d1 APTR mem, register __d2 struct PluginInit *plg)
- {
- /* Free all space allocated with FXPlug_InitPlug */
- initfunc(plg);
- if (mem)
- {
- CstFreeVec(mem);
- }
- }
-
- /* Filter
- If the Plugin is a filter, you`ll need to fill this section with
- your own routines */
-
- void __saveds ASM FXPlug_Filter(register __d1 struct PluginFilter *plf)
- {
- APTR myplugdata;
- UBYTE *p_t, *p_f;
- long max, i;
-
- struct fsbitmap *fsb;
- struct settings *st=plf->PluginData;
-
- initfunc(plf->pli);
-
- myplugdata =plf->PluginData;
- fsb =plf->fsb;
-
- max=fsb->width*fsb->height*3;
-
- p_t = p_f = (UBYTE *) fsb->location;
-
- /* Of course you could replace this with a more efficient
- routine, but for showing on how to do filters, this code
- should be understandable :) */
-
- for (i=0;i<max;i++)
- {
- *p_t++ = *p_f++ ^ st->xor_value;
- }
- }
-
- /* .. and here is the GUI-Stuff for our XOR-effect .. */
-
- #define GAD_XOR_VAL 1L
- #define GAD_XOR_PER 2L
-
- void __saveds ASM FXPlug_OpenFilterGUI (register __d1 struct PluginGUI *pog)
- {
- struct Gadget *gads;
- long win = pog->yourwin;
- long gui_ghei = pog->gui_ghei;
- long gui_gsep = pog->gui_gsep;
- struct settings *st=pog->PluginData;
- FXGUI *fx_gui;
-
- initfunc(pog->pli);
- fx_gui=pog->fxp_gui;
-
- gads=gui_crflexgad(&fx_gui->glist, win, GAD_DISTX, GAD_DISTY+5, 10, 200,
- GAD_XOR_VAL, GUI_SLIDER , 0, 0, 255,st->xor_value, 0, "XOR value" ,FLEX_NEXT,
- 0L , GUI_VERTSPACE , 0, 4, 4, 4, 0, "" ,FLEX_NEXT,
- GAD_XOR_PER, GUI_ONEBUTTONBAR , 0, 1, 100, 0,40, "Perform" ,FLEX_LAST);
-
- if (fx_gui->win=gui_openfix("XOR",STD_SIZESLIDE_IDCMP,win,0,0,0,0))
- {
- GT_RefreshWindow(fx_gui->win, NULL);
- gui_drboxsel (win, GAD_DISTX, GAD_DISTY,
- fx_gui->min_iw-4,
- fx_gui->min_ih-3-2-((gui_ghei+gui_gsep)*1));
- }
- }
-
- void __saveds ASM FXPlug_HandleFilterGUI (register __d1 struct PluginGUI *pog)
- {
- struct IntuiMessage *imsg;
- ULONG imsgClass;
- UWORD imsgCode;
- BOOL realtime = pog->realtime;
- struct settings *st=pog->PluginData;
- FXGUI *fx_gui;
-
- initfunc(pog->pli);
- fx_gui=pog->fxp_gui;
-
- imsg=pog->imsg;
-
- imsgClass = imsg->Class;
- imsgCode = imsg->Code;
- GT_ReplyIMsg(imsg);
-
- switch (imsgClass)
- {
- case IDCMP_IDCMPUPDATE:
- case IDCMP_GADGETDOWN:
- case IDCMP_GADGETUP:
- switch(GADGETID(imsg))
- {
- case GAD_XOR_VAL:
- st->xor_value = gui_get_slider(get_myfxwinid(), GAD_XOR_VAL);
- if (!realtime) {break;}
-
- case GAD_XOR_PER:
- fx_recalc();
- break;
- }
- break;
-
- case IDCMP_CLOSEWINDOW:
- gui_closenfree(get_myfxwinid());
- break;
- }
- }
-
- void __saveds ASM FXPlug_CloseFilterGUI (register __d1 struct PluginGUI *pog)
- {
- /* Optional by now .. not used! */
- }
-
- /********* I/O Stuff - additional loaders and savers as Plugin ************/
- /**** Loader ****/
-
- /* This routine is for checking, whether a file can be read by our plugin. */
- struct PluginImageInfo * __saveds ASM FXPlug_Identify_Image(register __d1 struct PluginIdent *pid)
- {
- struct PluginImageInfo *pii=NULL;
-
- initfunc(pid->pli);
-
- /* Search "Example" within the first ten characters */
- if (fx_find_str_in_buf(pid->header_data, 10, "Example"))
- {
- /* Found ! */
- if (pii=CstAllocVec(sizeof(struct PluginImageInfo), MEMF_ANY|MEMF_CLEAR))
- {
- pii->identified=TRUE;
- pii->size_identified=FALSE;
- }
- }
-
- /* You can also simply return NULL, if you couldn`t identify the pic! */
- return(pii);
- }
-
- /* This routine finally loads an image identified with FXPlug_Identify_Image */
- struct fsbitmap * __saveds ASM FXPlug_Load_Image(register __d1 struct PluginLoadImage *pli)
- {
- struct fsbitmap *fsb=NULL;
- UBYTE *p_t;
- long i, max;
-
- initfunc(pli->pli);
-
- /* Allocate fsbitmap with 100 * 100 pixels ! The
- returned fsbitmap HAS to be allocated this way!! */
- if (fsb=fs_allocbitmap(256,256,3))
- {
- p_t = (UBYTE *) fsb->location;
-
- max=256*256;
-
- for (i=0;i<max;i++)
- {
- *p_t++ = ((i*255)/max); /* R */
- *p_t++ = 128; /* G */
- *p_t++ = (255-((i*255)/max)); /* B */
- }
- }
-
- return(fsb);
- }
-
- /**** Image Saver ****/
- /* This one is really easy! Save an image in the format your plugin may or may not support. */
- BOOL __saveds ASM FXPlug_Save_Image(register __d1 struct PluginSaveImage *psi)
- {
- char *file_name=psi->file_name;
- struct fsbitmap *fsb=psi->fsb;
- BPTR p_out;
-
- initfunc(psi->pli);
-
- if (p_out=Open(file_name, MODE_READWRITE))
- {
- FPrintf(p_out,"P6\n%ld %ld\n# Written by example.plugin\n255\n",
- fsb->width,
- fsb->height);
- FWrite(p_out, fsb->location, fsb->width * fsb->height * fsb->type, 1);
- Close(p_out);
- return(TRUE);
- }
-
- return(FALSE);
- }
-
- /**** Custom GUI-routine for handling events, if you added message-port ****
- **** to the internal fxPAINT-routines! ****/
- void __saveds ASM FXPlug_Handle_Ports(register __d1 struct PluginHandlePorts *php)
- {
- struct IntuiMessage *imsg;
- ULONG imsgClass;
- UWORD imsgCode;
- struct handle_struct *hs;
-
- initfunc(php->pli);
- if (hs=php->pli->plugin_space)
- {
- if (hs->win)
- {
- while (hs->win!=NULL ?
- (imsg = GT_GetIMsg(hs->win->UserPort))
- : FALSE)
- {
- imsgClass = imsg->Class;
- imsgCode = imsg->Code;
- GT_ReplyIMsg(imsg);
-
- switch (imsgClass)
- {
- case IDCMP_CLOSEWINDOW:
- remport_sigmask(hs->win->UserPort->mp_SigBit,php->pli->pluginid);
- CloseWindow(hs->win);
- hs->win=NULL;
- break;
-
- case IDCMP_NEWSIZE:
- fxp_drawscaledfsb(hs->win, get_gui_screen(), hs->content, 0, 0, hs->win->GZZWidth, hs->win->GZZHeight);
- break;
- }
- }
- }
- }
- }
-
- /**** Launchable Plugins - e.g. for launching the Plugin`s GUI ****/
- BOOL __saveds ASM FXPlug_Launch(register __d1 struct PluginLaunch *pll)
- {
- struct handle_struct *hs;
-
- initfunc(pll->pli);
- if (hs=pll->pli->plugin_space)
- {
- if (!hs->content)
- {
- hs->content=fxp_loadpic("GUIpics/About.gfx");
- }
-
- if ((!hs->win) && (hs->content))
- {
- hs->win = OpenWindowTags(
- NULL,
- WA_InnerWidth, hs->content->width,
- WA_InnerHeight, hs->content->height,
- WA_Top, 10,
- WA_Left,10,
- WA_MaxWidth, ~0,
- WA_MaxHeight, ~0,
- WA_Activate, TRUE,
- WA_DragBar, TRUE,
- WA_DepthGadget, TRUE,
- WA_CloseGadget, TRUE,
- WA_SizeGadget, TRUE,
- WA_SmartRefresh, TRUE,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE,
- WA_Title, "example.plugin · Only fxPAINT makes it possible!",
- WA_GimmeZeroZero, TRUE,
- WA_CustomScreen, get_gui_screen(),
- WA_ScreenTitle, "example.plugin-window :)",
- TAG_DONE, 0);
-
- if (hs->win)
- {
- addport_sigmask(hs->win->UserPort->mp_SigBit, pll->pli->pluginid);
- fxp_drawfsb(hs->win, get_gui_screen(), hs->content, 0, 0);
- return(TRUE);
- }
- }
- }
- return(FALSE);
- }
-
- /**** Display Driver - sounds important and in fact, it is :)
- If you want to write own, fast(er) replacement routines for
- fxPAINT screen drawing routines or want to add some new stuff,
- this is your chance! If you should encounter problems such as
- fxPAINT crashing when it uses your routines, try the SAS/C-compiler-
- flags structureequivalents and nostackcheck ..
- If fsb->type==3 -> RGB-truecolor-data
- If fsb->type==1 -> Grayscale-data
- *****/
-
- BOOL __saveds ASM FXPlug_rendergfx_rp(register __d1 struct RastPort *rp, register __d2 struct Screen *scr, register __d3 struct fsbitmap *fsb, register __d4 long xpos, register __d5 long ypos, register __d6 struct PluginInit *pli)
- {
- initfunc(pli);
-
- /* Demo-"Driver" drawing black boxes instead of graphical content */
- /* Active PLG_DISPLAYDRIVER in the flags to test this one .. */
-
- SetAPen(rp,1);
- RectFill(rp, xpos, ypos, xpos+fsb->width, ypos+fsb->height);
-
- return(TRUE);
- }
-
- BOOL __saveds ASM FXPlug_PluginSetRegister (register __d1 struct PluginReg *pr)
- {
- return(FALSE);
- }
-
-